/*
 * Copyright (C) 2019 ByteDance Inc
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bytedance.scene.navigation;

import com.bytedance.scene.Scene;
import com.bytedance.scene.animation.NavigationAnimationExecutor;
import com.bytedance.scene.interfaces.PushResultCallback;
import ohos.utils.Parcel;
import ohos.utils.Sequenceable;

/**
 * Created by JiangQi on 7/30/18.
 */
class Record implements Sequenceable {
    Scene mScene;
    boolean mIsTranslucent;
    AbilityStatusRecord mAbilityStatusRecord;
    NavigationAnimationExecutor mNavigationAnimationExecutor;
    Object mPushResult;
    PushResultCallback mPushResultCallback;
    String mSceneClassName;

    public boolean marshalling(Parcel out) {
        return out.writeBoolean(mIsTranslucent) &&
                out.writeString(mSceneClassName);
    }

    public boolean unmarshalling(Parcel in) {
        this.mIsTranslucent = in.readBoolean();
        this.mSceneClassName = in.readString();
        return true;
    }

    public static final Sequenceable.Producer PRODUCER = new Sequenceable.Producer() {
        public Record createFromParcel(Parcel in) {
            // Initialize an instance first, then do customized unmarshlling.
            Record instance = new Record();
            instance.unmarshalling(in);
            return instance;
        }
    };


    public static Record newInstance(Scene scene, boolean isTranslucent, NavigationAnimationExecutor navigationAnimationExecutor) {
        Record record = new Record();
        record.mScene = scene;
        record.mSceneClassName = scene.getClass().getName();
        record.mIsTranslucent = isTranslucent;
        record.mNavigationAnimationExecutor = navigationAnimationExecutor;
        return record;
    }

    public void saveAbilityStatus() {
        mAbilityStatusRecord = AbilityStatusRecord.newInstance(mScene.requireAbility());
    }
}
